<!DOCTYPE html>
<html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" xmlns:th="http://www.thymeleaf.org">
<meta name=viewport
    content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,minimal-ui">
<meta name="apple-mobile-web-app-capable" content="yes">

<head>
    <th:block th:include="include :: header('片库列表')" />
    <th:block th:include="include :: layout-latest-css" />

</head>

<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
            </div>
            <div class="ui-layout-content">
                <div class="ztree" id="tree"></div>
            </div>
        </div>
    </div>

    <div class="ui-layout-center">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="user-form">
                        <input id="categoryId" name="categoryId" type="hidden">
                        <input id="parentId" name="parentId" type="hidden">

                        <div class="select-list">
                            <ul>
                                <li>
                                    资源名称：<input name="name" type="text" />
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                            class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                            class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:shipin:add">
                        <i class="fa fa-plus"></i> 新增
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.editTab()"
                        shiro:hasPermission="system:shipin:edit">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
                        shiro:hasPermission="system:shipin:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                </div>

                <div class="col-sm-12 select-table table-striped">
                    <table data-mobile-responsive="true" id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>


    <div class="ibox-content">
        <button class="btn btn-primary" type="button" id="btnModal">模态窗体</button>
        <div aria-hidden="true" class="modal inmodal" id="myModal4" role="dialog" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content animated fadeIn">
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal" type="button"><span
                                aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                        </button>
                    </div>
                    <div class="modal-body">
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-white" data-dismiss="modal" type="button">关闭</button>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:shipin:edit') }]];
        var resetPwdFlag = [[${@permission.hasPermi('system:user:resetPwd') }]];
        var removeFlag = [[${@permission.hasPermi('system:shipin:remove') }]];
        var datas = [[${@dict.getType('sys_normal_disable') }]];

        var prefix = ctx + "system/shipin";
        console.log(ctx);
        $(function () {
            queryUserList();

        });

        function queryUserList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "视频",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id'
                },
                {

                    title: '资源名称',
                    formatter: function (value, row, index) {
                        return subString(row.name, 10);
                    }
                },

                {
                    field: 'money',
                    title: '价格/单位(元)',
                    sortable: true
                },
                {
                    field: 'cs',
                    title: '打赏人数',
                },
                {
                    field: 'status',
                    title: '状态',
                    align: "left",
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(datas, item.status);
                    }
                },
                {
                    field: 'categoryName',
                    title: '类目',
                },

                {
                    field: 'url',
                    title: '图片链接',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.logo);
                    }
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + resetPwdFlag + '" href="javascript:void(0)" onclick="myOpen(\'' + row.id + '\')"><i class="fa fa-key"></i>预览</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        }

        function myOpen(id) {
            var url = prefix + '/preview/' + id;
            $.modal.open("预览视频", url, '500', '400');
        }

        function resetPwd(videoUrl) {
            $("#myModal4").modal("toggle");
        }
        $('#myModal4').on('hide.bs.modal', function (e) {
            console.log(e);
        });


        $('#btnExpand').click(function () {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function () {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        //超过长度的字符截取指定长度，超出部分以...显示
        function subString(str, len) {
            var newLength = 0;
            var newStr = "";
            var chineseRegex = /[^\x00-\xff]/g;
            var singleChar = "";
            var strLength = str.replace(chineseRegex, "**").length;
            if (strLength > len) {
                for (var i = 0; i < strLength; i++) {
                    singleChar = str.charAt(i).toString();
                    if (singleChar.match(chineseRegex) != null) {
                        newLength += 2;
                    }
                    else {
                        newLength++;
                    }
                    if (newLength > len) {
                        break;
                    }
                    newStr += singleChar;
                }

                if (strLength > len) {
                    newStr += "...";
                }
            } else {
                newStr = str;
            }
            return newStr;
        }


        /* 用户状态显示 */
        function statusTools(row) {
            if (row.status == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }

        /* 用户管理-停用 */
        function disable(id) {
            $.modal.confirm("确认要停用吗？", function () {
                $.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
            })
        }

        /* 用户管理启用 */
        function enable(id) {
            $.modal.confirm("确认要启用吗？", function () {
                $.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
            })
        }

    </script>
</body>

</html>